//
//  ViewController.swift
//  swiftOfAfn
//
//  Created by Mikey on 16/10/13.
//  Copyright © 2016年 mikey. All rights reserved.
//

import UIKit


class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        initView()
    }
    
    func initView () {
        let btn = UIButton(frame: CGRect(x: 10, y: 50, width: 100, height: 30))
        btn.backgroundColor = UIColor.red
        btn.addTarget(self, action: #selector(clickDown(_:)), for: .touchUpInside)
        btn.elementString = "第一个按钮"
        btn.element()["obj"] = "goodsssss"
        view.addSubview(btn)
        
        let btn2 = UIButton(frame: CGRect(x: 150, y: 50, width: 100, height: 30))
        btn2.backgroundColor = UIColor.red
        btn2.addTarget(self, action: #selector(cancel(_:)), for: .touchUpInside)
        view.addSubview(btn2)
        
        var arr = [UIButton]()
        for i in 0...10 {
            
            let btn = UIButton(frame: CGRect(x: 0, y: 0, width: 100, height: 35))
            btn.backgroundColor = UIColor.red
            btn.setTitle("annniu\(i)\(i)", for: .normal)
            btn.sizeToFit()
            arr.append(btn)
        }
        
//        let viewF = MCFlowButtonView()
//        viewF.backgroundColor = UIColor.lightGray
//        viewF.initWithButtonList(buttonList: arr)
//        viewF.frame = CGRect(x: 0, y: 100, width: 350, height: 100)
//        let _ = viewF.refreshFrame()
//        view.addSubview(viewF)
        
        let view1 = UIView(frame: CGRect(x: 0, y: 0, width: 300, height: 180))
        view1.backgroundColor = UIColor.red
        
        let view2 = UIView(frame: CGRect(x: 0, y: 0, width: 300, height: 180))
        view2.backgroundColor = UIColor.blue
        
        let view3 = UIView(frame: CGRect(x: 0, y: 0, width: 300, height: 180))
        view3.backgroundColor = UIColor.orange
        
        let view4 = UIView(frame: CGRect(x: 0, y: 0, width: 300, height: 180))
        view4.backgroundColor = UIColor.brown
        
        let bb = [view1, view2, view3, view4]
        // 滚动图
        let banner = MCMenuTable(frame: CGRect(x: 20, y: 100, width: 300, height: 180))
        banner.backgroundColor = UIColor.lightGray
        banner.addSubViews(arr: bb)
        view.addSubview(banner)
    }
    
    func cancel(_ sender: UIButton) {
        HTTPClient.cancelSigleTask(httpName: "bbj")
    }
    
    func clickDown(_ sender: UIButton) {
        
        
        let ss = "bbj"
        let bb = "bbjssskk"
        if (bb.hasPrefix("bbj")) {
            print("asss")
        } else {
            print("12312321")
        }
        print("输出 = \(sender.elementString), \(sender.element()["obj"])")
        
        let dic = sender.element();
        // http://182.106.194.94/d1.baidupcs.com/file/9f98d5487d7ae04c6b77904a45d509d7?bkt=p2-nj-609&xcode=3e6f721953d62ebbf8e490b0022f09e82de3377e2b47984b0967cef3f0948c81&fid=3726634679-250528-619955791047791&time=1476406731&sign=FDTAXGERLBH-DCb740ccc5511e5e8fedcff06b081203-BMuqb8pHcAAxnkm1T7B8X42RwcY=&to=lc&fm=Nin,B,T,t&sta_dx=1256871339&sta_cs=1287420&sta_ft=dmg&sta_ct=7&sta_mt=7&fm2=Ningbo,B,T,t&newver=1&newfm=1&secfm=1&flow_ver=3&pkey=0000d707a6c5b477f21cb0a8f02f4d8c2e0e&sl=72679502&expires=8h&rt=sh&r=329800179&mlogid=6665019118032074344&vuk=-&vbdid=515674651&fin=OfficeMac2011sp3.dmg&fn=OfficeMac2011sp3.dmg&slt=pm&uta=0&rtype=1&iv=0&isw=0&dp-logid=6665019118032074344&dp-callid=0.1.1&csl=138&csign=dcH2ELEohsWja62v1F8dulymHmU=&wshc_tag=0&wsts_tag=58002dcb&wsid_tag=7161b4dd&wsiphost=ipdbm

//        let url = "http://api.xfb315.com/v2/home/version?client=ios"
        let url = "http://localhost:8888/demo/apitest.php"
        
        print("\(type(of: self))")
//        for i in 0...10 {
            let _ = HTTPClient.get(url: url, params: nil, httpName: "sdf") { (res, data) in
                guard let anyObject = try? JSONSerialization.jsonObject(with: data as! Data, options: .mutableContainers) else {
                    return
                }
                print("obj:\(anyObject)");
            
        }

    }
    
    func addHttpName(_ httpName: String) -> String {
        let str = #file
        print("obj = \(str)")
        let arr = str.components(separatedBy: "/")
        var fileName = arr.last!
        fileName = "\(fileName)+\(httpName)"
        print("httpName = \(fileName) , dy")
        
        return fileName
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


}

